package com.ipay.controller;

import com.ipay.entity.LoginLogsEntity;
import com.ipay.service.LoginLogsService;
import com.ipay.utils.PageUtils;
import com.ipay.utils.Query;
import com.ipay.utils.R;
import jdk.nashorn.internal.runtime.options.LoggingOption;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 商户登录日志
 *
 * @author lanxiaofang
 * @email fang@lanxf.cn
 * @date 2017-12-14 14:52
 */


@Transactional
@Controller
@RequestMapping("/merchantLogs")
public class LoginLogsController extends AbstractController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private LoginLogsService loginLogsService;

    @RequestMapping("/{url}.html")
    public String page(@PathVariable("url") String url) {
        return "merchantLogs/" + url + ".html";
    }

    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/LoginLogs")
    @RequiresPermissions("merchantLogs:logs:list")
    public R list(@RequestParam Map<String, Object> params) {

        String merchantNo = getUser().getMerchantNo();
        //当查询的条件（商户编号）不为空的时候把查询条件加入，不然会把登入者的商户编号赋为空
        if(merchantNo != null){
            params.put("merchantNo", merchantNo);
        }
        //查询列表数据
        Query query = new Query(params);
        List<LoginLogsEntity> LoginLogList = loginLogsService.queryList(query);
        int total = loginLogsService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(LoginLogList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


}
